package com.lixm.netty.day2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Date;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author dc
 * @title: TimeServerHandle
 * @projectName netty
 * @date 2021/7/817:14
 */
public class ServerThreadPool {


    // 线程池对象
    private ThreadPoolExecutor executor;


    /**
     * 构造函数
     * @param maxPoolSize 最大线程数
     * @param timeout 超时时间
     */
    public ServerThreadPool(int maxPoolSize, int timeout) {
        executor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), maxPoolSize,120L, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(timeout));
    }

    /**
     * 执行线程
     * @param runnable
     */
    public void execute(Runnable runnable) {
        executor.execute(runnable);
    }


}
